import { useState } from "react";
import { makeFacade, RoomFacade } from "@/facade/roomFacade";
import { Assistant } from "@/models/LiveRoom";
import { useObservable } from '@/utils/rxHelpers';

type RoomHookTuple = [
  RoomFacade,
  string,
  string,
  string,
  Assistant[],
  string,
  number,
];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useRoomFacade(): RoomHookTuple {
  const [roomFacade] = useState(() => makeFacade());

  const [roomRole] = useObservable(roomFacade.roomRole$, "");
  const [anchorId] = useObservable(roomFacade.anchorId$, "");
  const [anchorName] = useObservable(roomFacade.anchorName$, "");
  const [assistants] = useObservable(roomFacade.assistants$, []);
  const [picUrl] = useObservable(roomFacade.picUrl$, "");
  const [status] = useObservable(roomFacade.status$, 0);

  //实在长得让人无力吐槽
  return [
    roomFacade,
    roomRole,
    anchorId,
    anchorName,
    assistants,
    picUrl,
    status
  ];
}
